<?php
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// The Pligg Team <pligger at pligg dot com>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
// 		http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".

	global $main_smarty, $cached_totals, $new_search, $cached_links, $current_user, $cached_saved_links, $fetch_link_summary;
	
	$new_hunt =  new Hunt();
	$new_hunt->linkid = $id;
	$new_hunt->read();
	$huntid = $new_hunt->id;

	$rows = $db->get_var("SELECT count(*) FROM " . table_apply . " WHERE  apply_stage!='discard' AND apply_hunt_id=$huntid ");
	if ($rows > 0) {
		//die("SELECT apply_link_id FROM " . table_apply . " WHERE  apply_stage!='discard' AND apply_hunt_id=$huntid ");
		$links = $db->get_col("SELECT apply_link_id FROM " . table_apply . " WHERE  apply_stage!='discard' AND apply_hunt_id=$huntid ");
	
		if(!isset($apply_summary_output)){$apply_summary_output = '';}
		if ($links) {
			$link = new Link;
			foreach($links as $link_id) {
				$link->id=$link_id;
				$link->read();
				$apply_summary_output .= '<div style="padding:10px 5px; border-bottom:1px solid #ccc;">';
				$apply_summary_output .= $link->print_summary_view_apply('full', true);
				$apply_summary_output .= $link->get_votes(true);
				$apply_summary_output .= $link->get_comments(true);
				//comment form here
				if ($current_user->authenticated) {
					//$apply_summary_output .= $main_smarty->fetch($the_template . '/comment_form.tpl');
					//because we need the linkid in tpl, so put in the function get_commnets()
				}
				else {
					$loginurl = getmyurl("login", my_base_url .my_pligg_base . '/story.php?' . $_SERVER['QUERY_STRING']);
					$apply_summary_output .= '<div align="center" style="clear:both;margin-left:auto;font-weight:bold;margin-right:auto;border-color:#ccc; border-style:solid; border-width:1px;width:400px;text-align:center; padding-bottom: 8px;">
			请<a href="'. $loginurl .'">登录</a>后再发表评论！ 新用户请先 <a href="register.php">注册</a>.
		</div>';
				}
				$apply_summary_output .= "</div>";//end of comment form
				$apply_summary_output .= '</div>';
				$apply_summary_output .= "<p>&nbsp</p>";
			}
		}
	
		if(isset($fetch_link_summary) && $fetch_link_summary == true){
			$main_smarty->assign('apply_summary_output', $apply_summary_output);
		} else {	
			echo $apply_summary_output;
		}
	}
?>
